package cn.edu.csust.cvs.management.common;

import cn.edu.csust.cvs.management.exception.ErrorCode;

/**
 * @Auther: snail
 * @Date: 2021/1/22 00:30
 * @Description: 基础响应对象
 */
public class ApiResponse {

    private static final String CODE = "0";

    private static final String MSG = "ok";

    private boolean success;

    private String code;

    private String msg;

    public ApiResponse(){

    }

    public ApiResponse(boolean success, String code, String msg) {
        this.success = success;
        this.code = code;
        this.msg = msg;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static ApiResponse ok() {
        return new ApiResponse(Boolean.TRUE, CODE, MSG);
    }

    public static ApiResponse error(ErrorCode errorCode){
        return new ApiResponse(Boolean.FALSE, errorCode.getErrorCode(), errorCode.getErrorMsg());
    }
}
